import MathUtil from '@/MathUtil';
import EffectCommon from 'code/Core/Common/EffectCommon';
import MovementCommon from 'code/Core/Common/MovementCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 偷袭
 **/
export default class DZ_SneakAttack extends AbilityBase {
    static instance: DZ_SneakAttack;
    constructor(id: string = 'Atx1') {
        super(id);
        DZ_SneakAttack.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let { x: ox, y: oy } = MathUtil.polarProjection(tarX, tarY, 600, GetUnitFacing(target) - 180);
        SetUnitX(source, ox);
        SetUnitY(source, oy);
        let { x: tx, y: ty } = MathUtil.polarProjection(tarX, tarY, 50, GetUnitFacing(target) - 180);
        let angle = MathUtil.angleBetweenCoords(ox, oy, tx, ty);
        MovementCommon.hitFly({
            caster: source,
            target: source,
            distance: MathUtil.distanceBetweenPoints(ox, oy, tx, ty),
            speed: 1200,
            maxHeight: 150,
            angle,
            other: target,
            onEnd: this.onHitFlyEnd.bind(this),
            onInterval: this.hitFlyInterval.bind(this),
        });
    }
    hitFlyInterval(p: HitFlyConfig) {
        EXSetUnitFacing(p.target, p.angle);
        EffectCommon.残影特效({
            model: SLKCommon.getUnitModel(p.caster),
            duration: 0.4,
            x: p.curX,
            y: p.curY,
            angle: p.angle,
        });
    }
    onHitFlyEnd(p: HitFlyConfig) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = UnitCommon.取攻击(p.caster) * (0.25 + 0.25 * lv) + 50 * lv;
        DamageSystemInstance.applyPhysicalDamage(p.other, p.caster, dmg, this.id);
        StunSystemIntance.stun(p.other, 2, p.caster);
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
}
